package itheima.com.SocketTCPImg;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

public class ReSocketServe {

    public static void main(String[] args) throws Exception {

        ServerSocket serverSocket = new ServerSocket(8888);
        Socket accept = serverSocket.accept();
        System.out.println("服务端发送");

        String filePath = "D:\\一条小团团\\thisImg.jpg";
        BufferedInputStream bufferedInputStream = new BufferedInputStream(accept.getInputStream());

        byte[] bytes = StreamUtils.streamToByteArray(bufferedInputStream);

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
        bos.write(bytes);


//        发送 “收到图片"
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bufferedWriter.write("收到图片");
        bufferedWriter.flush();
        accept.shutdownOutput();


        bufferedWriter.close();

        bos.close();
        bufferedInputStream.close();
        accept.close();
        serverSocket.close();

    }


}
